import React from "react";
import ReactDom from "react-dom";
import {Link} from "react-router-dom";
import {Card} from 'antd';

import {REQUEST} from "../util/comm.jsx";
const _request=new REQUEST();

class PCJoke extends React.Component{
	constructor(){
		super();
		this.state={
			joke:''
		}
	}
	componentDidMount(){
		this.getWeiChatArticle();
	}
	// 请求数据
	getWeiChatArticle(){
		let url='./data/weixin.json';
		_request.get(url,{}).then(res=>res.json()).then(json=>{
			this.setState({
				joke:this.filter(json.result.list,0,4)
			})
		})
	}
	// 数组截取
	filter(array,start,end){
		if(array.length<=(end-start))
			return array
		else
			return array.slice(start,end);
	}
	render(){
		return(
			<div className="joke-module">
				<Card title='微信头条'>
					<ul className="joke-list">
						{
							this.state.joke?
							this.state.joke.map((jokeItem,index)=>{
								return(
									<li key={index} >
										<a href={jokeItem.url} target='_blank'>{jokeItem.title}-[{jokeItem.source}]</a>
									</li>
								)
							}):null

						}
					</ul>
				</Card>
			</div>
		)
	}
}
export default PCJoke;

